package com.yunding.house.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yunding.house.mapper.HouseResourcesMapper;
import com.yunding.house.pojo.HouseResources;
import com.yunding.house.service.HouseResourcesService;
import com.yunding.house.utils.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 房源表 服务实现类
 * </p>
 *
 * @author jobob
 * @since 2019-08-14
 */
@Service
public class HouseResourcesServiceImpl implements HouseResourcesService {


    @Autowired
    private HouseResourcesMapper houseResourcesMapper;

    public void save(HouseResources houseResources) {
        houseResourcesMapper.insert(houseResources);
    }

    public void del(long id) {
        houseResourcesMapper.deleteById(id);
    }

    public void update(HouseResources houseResources) {
        houseResourcesMapper.updateById(houseResources);
    }

    public List<HouseResources> findALL() {
        return houseResourcesMapper.selectList(null);
    }

    public PageResult search(int page, int size, HouseResources houseResources) {

        Page<HouseResources> page1 = new Page<HouseResources>(page,size);

        QueryWrapper queryWrapper = new QueryWrapper(new HouseResources());

        queryWrapper.like("title",houseResources.getTitle());

        IPage iPage = houseResourcesMapper.selectPage(page1, queryWrapper);
        return new PageResult(iPage.getTotal(),iPage.getRecords());
    }
}
